package com.online.olsrootserver.service.impl;

import com.online.olsrootserver.entity.Message;
import com.online.olsrootserver.service.MessageService;
import com.online.olsrootserver.slave0.Message0Mapper;
import com.online.olsrootserver.slave1.Message1Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by littleheng on 2018/4/27
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private Message0Mapper message0Mapper;

    @Autowired
    private Message1Mapper message1Mapper;

    @Override
    public List<Message> getMessageList(String companyId, String sessionId) {
        int mod = Integer.parseInt(companyId) % 2;
        if (mod == 0) {
            return this.message0Mapper.getMessageList(sessionId);
        } else {
            return this.message1Mapper.getMessageList(sessionId);
        }
    }

    @Override
    public int addMessage(Message message) {
        if (Integer.parseInt(message.getCompanyId()) % 2 == 0) {
            return this.message0Mapper.insertMessage(message);
        } else {
            return this.message1Mapper.insertMessage(message);
        }
    }
}